package com.gg.fruit.controller;

import base.BaseServlet;
import com.gg.entity.Fruit;
import com.gg.entity.User;
import com.gg.fruit.service.FruitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/GetAllFruitsServlet")
public class GetAllFruitsServlet extends BaseServlet {
    @Autowired
    private FruitService fruitService;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取想要的第几页
        Integer pageNum=Integer.parseInt(request.getParameter("pageNum"));
        //分页
        PageHelper.startPage(pageNum,8);
        //业务层查询数据库后 返回结果集
        List<Fruit> fruits=fruitService.getAllFruits();
        //把分页信息封装成 info对象
        PageInfo<Fruit> info=new PageInfo<>(fruits);
        //把分页信息放到session中
        request.getSession().setAttribute("fruitsInfo",info);
        request.getSession().setAttribute("isHot",false);
        response.sendRedirect("/fruits/admin/BSindex4.jsp");
    }
}
